<!DOCTYPE html>
<html>
  <head>
    <title>Insurance quoting</title>

      <link href="assets/css/700.css" rel="stylesheet">
      <link rel="stylesheet" href="assets/css/fontawesome-all.min.css">
      <script src="js/jQuery.min.js"></script>
      <script src="js/jquery.validate.min.js"></script>

      <script src="js/jquery.steps.js"></script>

    <style>
      html, body {
      min-height: 100%;
      }
      body, div, form, input, select, textarea, label, p { 
      padding: 0;
      margin: 0;
      outline: none;
      font-family: Roboto, Arial, sans-serif;
      font-size: 14px;
      color: #666;
      line-height: 22px;
      }
      h1 {
      position: absolute;
      margin: 0;
      font-size: 40px;
      color: #fff;
      z-index: 2;
 line-height: 83px;
      }
      textarea {
      width: calc(100% - 12px);
      padding: 5px;
      }
      .testbox {
      display: flex;
      justify-content: center;
      align-items: center;
      height: inherit;
      padding: 20px;
      }
      form {
      width: 100%;
      padding: 20px;
      border-radius: 6px;
      background: #fff;
      box-shadow: 0 0 8px #006622; 
      }
      .banner {
      position: relative;
      height: 300px;
          background-image: url("images/Taylor.png");
      // background-size: cover;
          background-repeat: no-repeat;
          background-position: center;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
      }
      .banner::after {
      content: "";
      background-color: rgba(0, 0, 0, 0.2); 
      position: absolute;
      width: 100%;
      height: 100%;
      }
      input, select, textarea {
      margin-bottom: 10px;
      border: 1px solid #ccc;
      border-radius: 3px;
      }
      input {
      width: calc(100% - 10px);
      padding: 5px;
      }
      input[type="date"] {
      padding: 4px 5px;
      }
      textarea {
      width: calc(100% - 12px);
      padding: 5px;
    }
      .item:hover p, .item:hover i, .question:hover p, .question label:hover, input:hover::placeholder {
      color:  #006622;
      }
      .item input:hover, .item select:hover, .item textarea:hover {
      border: 1px solid transparent;
      box-shadow: 0 0 3px 0  #006622;
      color: #006622;
      }
      .item {
      position: relative;
      margin: 10px 0;
      }
      .item span {
      color: red;
      }
      input[type="date"]::-webkit-inner-spin-button {
      display: none;
      }
      .item i, input[type="date"]::-webkit-calendar-picker-indicator {
      position: absolute;
      font-size: 20px;
      color: #00b33c;
      }
      .item i {
      right: 1%;
      top: 30px;
      z-index: 1;
      }
 .week {
      display:flex;
      justfiy-content:space-between;
      }
      .colums {
      display:flex;
      justify-content:space-between;
      flex-direction:row;
      flex-wrap:wrap;
      }
      .colums div {
      width:48%;
      }
      [type="date"]::-webkit-calendar-picker-indicator {
      right: 1%;
      z-index: 2;
      opacity: 0;
      cursor: pointer;
      }
      input[type=radio], input[type=checkbox]  {
      display: none;
      }
      label.radio {
      position: relative;
  display: inline-block;
      margin: 5px 20px 15px 0;
      cursor: pointer;
      }
      .question span {
      margin-left: 30px;
      }
      .question-answer label {
      display: block;
      }
      label.radio:before {
      content: "";
      position: absolute;
      left: 0;
      width: 17px;
      height: 17px;
      border-radius: 50%;
      border: 2px solid #ccc;
      }
      input[type=radio]:checked + label:before, label.radio:hover:before {
      border: 2px solid  #006622;
      }
      label.radio:after {
      content: "";
      position: absolute;
      top: 6px;
      left: 5px;
      width: 8px;
      height: 4px;
      border: 3px solid  #006622;
      border-top: none;
      border-right: none;
      transform: rotate(-45deg);
      opacity: 0;
      }
      input[type=radio]:checked + label:after {
      opacity: 1;
      }
      .flax {
      display:flex;
      justify-content:space-around;
      }
      .btn-block {
      margin-top: 10px;
      text-align: center;
      }
      button {
      width: 150px;
      padding: 10px;
      border: none;
      border-radius: 5px; 
      background:  #006622;
      font-size: 16px;
      color: #fff;
cursor: pointer;
      }
      button:hover {
      background:  #00b33c;
      }
      @media (min-width: 568px) {
      .name-item, .city-item {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      }
      .name-item input, .name-item div {
      width: calc(50% - 20px);
      }
      .name-item div input {
      width:97%;}
      .name-item div label {
      display:block;
      padding-bottom:5px;
      }
      }
         
 .topnav {
  background-color: #333;
  overflow: hidden;
}

/* Style the links inside the navigation bar */
.topnav a {
  float: left;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

/* Change the color of links on hover */
.topnav a:hover {
  background-color: #ddd;
  color: black;
}

/* Add a color to the active/current link */
.topnav a.active {
  background-color: #4CAF50;
  color: white;
}

    </style>
  </head>
  <body>
    <div class="testbox">
      <form>
        <div class="banner">

        </div>
        <br/>    
              <div class="topnav">
  <a class="active" href="index.html">Home</a>
  <a href="dashboard.html">Dashboard</a>
  <a href="newpolicy.html">Contact</a>
  <a href="/login">Login</a>
  <a href="/logout">Logout</a>
              </div>
          <br>


          <fieldset>
          <legend></legend>
<p><b>Auto insurance</b></p>
          <div class="item">
            <label for="driverAge"> Driver Age<span>*</span></label>
            <input id="driverAge" type="number" name="driverAge" />
          </div>
          <div class="item">
            <label for="vehicleAge">Vehicle Age<span>*</span></label>
            <input id="vehicleAge" type="number" name="activity" />
          </div>
          <div class="item">
            <label for="accidentCount">Number of at fault accidents in loast 5 years<span>*</span></label>
            <input id="accidentCount" type="number" name="accidentCount" />
          </div>
            <div class="item">
             <label for="vehicleWorth">Insured Car Worth<span>*</span></label>
            <input id="vehicleWorth" type="number" name="vehicleWorth" />
          </div>
            
            
           <div class="item">
            <label>What type of area is the car garaged in?<span>*</span></label>
            <select id = "carGaragedArea">
              <option selected value="" disabled selected></option>
                  <option value="Dense Urban" >Dense Urban</option>
                  <option value="Urban">Urban</option>
                  <option value="Rural">Rural</option>
              </select>
          </div>
            <br>
            <div>
          <button type="calc" id="calc"  onclick="fire_ajax_submit_car()">Calculate</button>
                <br>
                <span id="result1"></span>

            </div>
 
            <hr>
<p><b>Home Insurance</b></p>
  <div class="item">
            <label for="homeAge">Age of home (in years)<span>*</span></label>
            <input id="homeAge" type="text" name="homeAge" />
          </div>
          <div class="item">
            <label>Type of House<span>*</span></label>
              <select id = "typeOfHouse">
              <option selected value="" disabled selected></option>
                  <option value="Single Dwelling" >Single Dwelling</option>
                  <option value="Apartment">Apartment</option>
                  <option value="Bungalow">Bungalow</option>
                  <option value="Semi-attached">Semi-attached</option>
            
              </select>
          </div>
            
          <div class="item">
            <label>Heating Type<span>*</span></label>
             <select id = "heatingType">
              <option selected value="" disabled selected></option>
                  <option value="Electric" >Electric</option>
                  <option value="Oil">Oil</option>
                  <option value="Wood">Wood</option>
                  <option value="Gas">Gas</option>
                  <option value="Other">Other</option>
              </select>
          </div>
                 <br>
         <div>
<span id="result"></span>
          <button type="calc" id="calc1"  onclick="fire_ajax_submit_home()">Calculate</button> 
        </div>
               </fieldset>
        <br/>
      </form>
    </div>
        
      <script>
          
    $("#calc").click(function(event){

        //stop submit the form, we will get it manually.
        event.preventDefault();
      //  fire_ajax_submit();
    });
          
           $("#calc1").click(function(event){

        //stop submit the form, we will get it manually.
        event.preventDefault();
      //  fire_ajax_submit();
    });
          
function fire_ajax_submit_car() {

    var driverAge = $("#driverAge").val();
    var vehicleAge = $("#vehicleAge").val();
    var accidents_last_5_years = $("#accidentCount").val();
    var insuredCarWorth = $("#vehicleWorth").val();
    var carGaragedArea = $("#carGaragedArea").val();
       
    var carData = {
            driverAge: driverAge,
            vehicleAge: vehicleAge,
            accidentCount:accidents_last_5_years,
            vehicleWorth:insuredCarWorth,
            location_type:carGaragedArea
        }
    
    var jsonCarData = JSON.stringify(carData);
     
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "http://localhost:8080/api/auto_premium_rating",
        dataType: 'json',
        contentType: 'application/json',
        data: jsonCarData,   
        cache: false,
        timeout: 600000,
        success: function (data) { 
            console.log(data);          
            $("#result1").text("You would pay: " + data.calculatedPremium);
        },
        error: function (e) {
            
            //  console.log( e );


          //  var json = "<h4>Ajax Response</h4>&lt;pre&gt;"
         //       + e.responseText + "&lt;/pre&gt;";
          //  $('#feedback').html(json);

          //  console.log("ERROR : ", e);
          //  $("#btn-search").prop("disabled", false);

        }
    });
}    
    function fire_ajax_submit_home() {
    var ageOfHome = $("#homeAge").val();
    var typeOfHouse = $("#typeOfHouse").val();
    var heatingType = $("#heatingType").val();
  
    var houseData = {
        homeAge: ageOfHome,
        heatingType: heatingType,
        dwellingType: typeOfHouse     
    }
    var jsonHouseData = JSON.stringify(houseData);
    console.log(jsonHouseData);  

    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "http://localhost:8080/api/home_premium_rating",
        dataType: 'json',
        contentType: 'application/json',
        data: jsonHouseData,   
        cache: false,
        timeout: 600000,
        success: function (data) {  
            console.log(data);              
            $("#result").text(data.calculatedPremium);
        },
        error: function (e) {
            
            //  console.log( e );


          //  var json = "<h4>Ajax Response</h4>&lt;pre&gt;"
         //       + e.responseText + "&lt;/pre&gt;";
          //  $('#feedback').html(json);

          //  console.log("ERROR : ", e);
          //  $("#btn-search").prop("disabled", false);

        }
    });
}          
      </script>
  </body>
       
</html>